import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:oramemo/common/styles/colors.dart';

import 'create_logic.dart';
import 'create_state.dart';

class CreatePage extends StatelessWidget {
  const CreatePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final CreateLogic logic = Get.put(CreateLogic());
    final CreateState state = Get.find<CreateLogic>().state;

    return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SizedBox(height: 28.h),
            Expanded(
              child: SingleChildScrollView(
                child: Padding(
                  padding: EdgeInsets.symmetric(horizontal: 23.w),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      _buildSectionHeader('回忆录', onTap: () => logic.onAddMemoir()),
                      SizedBox(height: 16.h),
                      _buildContentCard('在这里书写关于你的回忆录。'),
                      SizedBox(height: 48.h),
                      _buildSectionHeader('故事', onTap: () => logic.onAddStory()),
                      SizedBox(height: 16.h),
                      _buildContentCard('在这里记录你的一切故事'),
                      SizedBox(height: 20.h),
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildSectionHeader(String title, {required VoidCallback onTap}) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          title,
          style: TextStyle(
            fontSize: 18.sp,
            fontWeight: FontWeight.bold,
            color: Colours.app_main,
          ),
        ),
        GestureDetector(
          onTap: onTap,
          child: SizedBox(
            width: 30.w,
            height: 30.h,
            child: Icon(
              Icons.add,
              color: Colours.app_main,
              size: 24.r,
            ),
          ),
        ),
      ],
    );
  }

  Widget _buildContentCard(String hintText) {
    return Container(
      width: double.infinity,
      height: 150.h,
      decoration: BoxDecoration(
        color: Color(0xFFFAFAFA),
        borderRadius: BorderRadius.circular(24.r),
      ),
      padding: EdgeInsets.only(top:45.h),
      child: Text(
        hintText,
        style: TextStyle(
          fontSize: 16.sp,
          color: Color(0xFF979797),
        ),
        textAlign: TextAlign.center,
      ),
    );
  }
}
